<!-- 登录/注册 -->
<template>
	<view class="content page" :style="{ '--color': color }">
		<status-bar :title="type == 0 ? '注册' : '登录'"></status-bar>
		<view class="kite-bind-case">
			<view class="kite-bind-title">
				<text>{{ type == 0 ? '注册' : '登录' }}</text>
			</view>
		</view>
		<view class="kite-bind-case" style="margin-top: 40upx">
			<view class="kite-phone-case flex-box align-center">
				<text class="iconfont icon-iconzhengli_shouji"></text>
				<view class="kite-bind-input flex">
					<input
						type="text"
						class="inputPhone"
						v-model="v_user"
						placeholder="请输入账号" />
				</view>
			</view>
		</view>
		<view class="kite-bind-case">
			<view class="kite-email-case flex-box align-center">
				<text class="iconfont icon-mima1"></text>
				<view class="kite-bind-input flex">
					<input
						type="password"
						class="inputPhone"
						v-model="password"
						placeholder="请输入密码" />
				</view>
			</view>
		</view>
		<view class="kite-bind-case" v-if="type == 0">
			<view class="kite-email-case flex-box align-center">
				<text class="iconfont icon-mima1"></text>
				<view class="kite-bind-input flex">
					<input
						type="password"
						class="inputPhone"
						v-model="cfmPassword"
						placeholder="请确认密码" />
				</view>
			</view>
		</view>

		<view class="kite-bind-case">
			<view class="submitBtn btn3 thmeBg" @click="unMpBindPhone" v-if="type == 0">注册</view>
			<view class="submitBtn btn3 thmeBg" @click="unMpLogin" v-if="type == 1">登录</view>

			<view style="text-align: center; margin-top: 30upx; margin-bottom: 40upx">
				<text
					@click="chkType(0)"
					v-if="type == 1"
					class="thmeColor"
					style="text-decoration: underline"
					>还没有账号，去注册</text
				>
				<text
					@click="chkType(1)"
					v-if="type == 0"
					class="thmeColor"
					style="text-decoration: underline"
					>已有账号，直接登录</text
				>
			</view>
		</view>
	</view>
</template>
<script>
	var timer;
	import { mapState, mapMutations } from 'vuex';
	import API from '../../api/index.js';

	export default {
		data() {
			return {
				phoneNumber: '',

				act_id: '',
				session_key: '',
				showbtn: true,

				type: 1, // 1登录 0注册
				password: '',
				cfmPassword: '',
				disabled: true,
				userinfo_: false, // 是否已经授权 true已授权
				CouponShow: false,
				couponArry: '',
				v_user: '',
			};
		},

		onLoad(e) {
			if (e.type) this.type = e.type;
			this.type == 1 ? this.$BarTitle('账号登录') : this.$BarTitle('账号注册');
		},
		methods: {
			...mapMutations(['getUser']),
			chkType(n) {
				this.type = n;
				this.type == 1 ? this.$BarTitle('账号登录') : this.$BarTitle('账号注册');
			},

			/** 注册 **/
			unMpBindPhone: function () {
				if (!this.v_user) return this.$Toast('请输入账号');
				if (!this.password) return this.$Toast('请输入密码');
				if (!this.cfmPassword) return this.$Toast('请确认密码');

				if (this.password != this.cfmPassword) return this.$Toast('密码输入不一致~');

				const info = this.userInfo;
				let param = {
					v_user: this.v_user,
					password: this.password,
					password2: this.cfmPassword,
					share_v_id: this.share_v_id,
				};
				this.$http
					.post({
						url: '/zzj_singleSaleApi/fastApp',
						data: param,
					})
					.then((res) => {
						if (res.errcode != 100) return this.$Toast(res.msg);

						this.getUser({
							vid: res.v_id,
						});
						uni.setStorageSync('vid', res.v_id);
						this.$back();
					});
			},
			closeFunc() {
				that.CouponShow = false;
				uni.navigateBack({
					delta: 1,
				});
			},
			/** 登录 **/
			unMpLogin: function () {
				if (!this.v_user || this.v_user == ' ') {
					uni.showToast({
						title: '请输入账号',
						icon: 'none',
					});
					return;
				}

				if (!this.password || this.password == ' ') {
					uni.showToast({
						title: '请输入密码！',
						icon: 'none',
					});
					return;
				}

				this.$http
					.post({
						url: '/zzj_singleSaleApi/fastLogin',
						data: {
							v_user: this.v_user,
							password: this.password,
						},
					})
					.then((res) => {
						if (res.v_id) {
							this.getUser({
								vid: res.v_id,
							});
							uni.setStorageSync('vid', res.v_id);
							uni.navigateBack({
								delta: 1,
							});
						}

						if (res.errcode == 101) {
							uni.showToast({
								title: res.msg,
								icon: 'none',
							});
						}
					});
			},
		},
		computed: {
			...mapState(['color', 'openid', 'vid', 'bid', 'userInfo', 'share_v_id']),
		},
	};
</script>

<style scoped>
	.kite-bind-case {
		width: 100%;
		height: auto;
		overflow: hidden;
	}

	.kite-phone {
		position: absolute;
		left: 0;
		width: 15%;
		height: 100upx;
		text-align: center;
	}

	.kite-phone image {
		width: 40upx;
		height: 40upx;
		margin: 30upx 0;
	}

	.btn3 {
		width: 650upx;
		height: 88upx;
		line-height: 88upx;
	}

	.submitBtn.btn3 {
		margin-top: 40upx;
	}

	.kite-bind-tips {
		width: 100%;
		height: 50upx;
		font-size: 24upx;
		font-weight: 400;
		color: #ff4b4e;
		letter-spacing: 2upx;
		margin-top: 40upx;
		margin-left: 60upx;
	}

	.kite-onekey-btn {
		background: #ffffff;
		font-size: 28upx;
		font-weight: 400;
		color: #333333;
		text-align: center;
	}

	.kite-codeBtn {
		position: absolute;
		right: 0;
		line-height: 70upx;
		width: 160upx;
		text-align: center;
		color: #999;
		border-radius: 16upx;
		height: 70upx;
		float: right;
		border: 2upx solid #dddddd;
		font-size: 22upx;
		z-index: 8;
		bottom: 20upx;
	}

	.kite-bind-input {
		position: relative;
		height: 120upx;
		margin-left: 30upx;
		padding: 20upx 0;
		border: none;
	}

	.kite-bind-input:before {
		position: absolute;
		content: '';
		bottom: 0;
		background: #999999;
		width: 100%;
		height: 2upx;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
	}

	.kite-phone-case,
	.kite-email-case {
		position: relative;
		width: 100%;
		height: 140upx;
		padding: 10upx 0;
	}

	.kite-bind-case {
		padding: 0 50upx;
	}

	.kite-bind-title {
		width: 100%;
		font-size: 36upx;
		line-height: 82upx;
		color: #666666;
		text-align: center;
		letter-spacing: 4upx;
		font-weight: bold;
		padding-top: 90rpx;
	}

	.kite-bind-title text {
		color: #666666;
		font-size: 36upx;
	}

	.kite-case {
		margin-top: 60upx;
		width: 100%;
		height: 80upx;
	}

	.kite-one-button {
		width: 690upx;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		background: #ff4400;
		border-radius: 200upx;
		margin: 0 auto;
		font-size: 24upx;
		font-weight: 400;
		color: #ffffff;
	}

	.content {
		width: 100%;
		height: 100vh;
		background: #ffffff;
	}

	.inputText {
		width: 100%;
		padding: 0 30upx;
	}

	.inputBox,
	.inputNumber {
		width: 100%;
		height: 80upx;
	}

	.inputBox,
	.submitBtn {
		margin-top: 60upx;
	}

	.inputNumber {
		position: relative;
		border: none;
		/* border: 1upx solid #999999; */
		border-radius: 64upx;
		line-height: 80upx;
		padding: 0 30upx;
		margin-bottom: 40upx;
	}

	.inputNumber:before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		border: 1px solid #000;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		width: 200%;
		height: 200%;
		-webkit-transform: scale(0.5);
		transform: scale(0.5);
		-webkit-transform-origin: left top;
		transform-origin: left top;
	}

	.inputPhone {
		width: 100%;
		float: left;
		height: 48upx;
		margin-top: 16upx;
		margin-left: 20upx;
	}

	.inputCode .inputPhone {
		width: calc(50% - 30upx);
	}

	.inputCode {
		padding-right: 0;
	}

	.codeBtn {
		width: calc(50% - 30upx);
		text-align: center;
		color: #ffffff;
		border-radius: 0 64upx 64upx 0;
		background: #ff4400;
		height: calc(100% + 2upx);
		float: right;
		border: 2upx solid #ff4b4e;
	}

	.iconfont {
		font-size: 46rpx;
		color: #666;
		width: 46rpx;
		text-align: center;
	}
</style>
